package frontend.cehandler.compilationerrors;

import frontend.lexer.token.Token;
import frontend.parser.node.Node;

public class CompilationError implements Comparable<CompilationError> {
    private final int lineNumStart;
    private final int lineNumEnd;
    private final int linePosStart;
    private final int linePosEnd;
    private final String message;
    private final CEType errorType;
    private final CECause errorCause;
    private final Token causedToken;
    private final Node causedNode;
    @Override
    public String toString() {
        return String.valueOf(lineNumStart) + ' ' + errorType.toString();
    }

    public CompilationError(CECause errorCause,
                            CEType errorType,
                            String message,
                            int lineNumStart, int lineNumEnd, int linePosStart, int linePosEnd,
                            Token causedToken, Node causedNode) {
        this.errorCause = errorCause;
        this.errorType = errorType;
        this.message = message;
        this.lineNumStart = lineNumStart;
        this.lineNumEnd = lineNumEnd;
        this.linePosStart = linePosStart;
        this.linePosEnd = linePosEnd;
        this.causedToken = causedToken;
        this.causedNode = causedNode;
    }

    @Override
    public int compareTo(CompilationError compilationError) {
        int d_lineNum = this.lineNumStart - compilationError.lineNumStart;
        return d_lineNum == 0 ? this.linePosStart - compilationError.linePosStart : d_lineNum;
    }

    public int getLineNumStart() {
        return lineNumStart;
    }

    public int getLineNumEnd() {
        return lineNumEnd;
    }

    public int getLinePosStart() {
        return linePosStart;
    }

    public int getLinePosEnd() {
        return linePosEnd;
    }

    public String getMessage() {
        return message;
    }

    public CEType getErrorType() {
        return errorType;
    }

    public CECause getErrorCause() {
        return errorCause;
    }

    public Token getCausedToken() {
        return causedToken;
    }

    public Node getCausedNode() {
        return causedNode;
    }
}